// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of DOM3XPath
//
// DOM3XPath is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// DOM3XPath is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with DOM3XPath. If not, see <http://www.gnu.org/licenses/>.
//	
//
//   $Id$
// XPathHelper.h : Declaration of the CXPathHelper

#ifndef __XPATHHELPER_H_
#define __XPATHHELPER_H_

#include "resource.h"       // main symbols
#include "XPathResult.h"
//#define COUNT_HELPER 1
/////////////////////////////////////////////////////////////////////////////
// CXPathHelper
class ATL_NO_VTABLE CXPathHelper : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CXPathHelper, &CLSID_XPathHelper>,
	public IDispatchImpl<IXPathHelper, &IID_IXPathHelper, &LIBID_DOM3XPATHLib, 1, 1>
{
public:
		#ifdef COUNT_HELPER
			static unsigned long sm_Count;	
		#endif

	CXPathHelper():
		m_pResult(NULL)
	{
		#ifdef COUNT_HELPER
			++sm_Count;	
		#endif
	}
	virtual ~CXPathHelper()
	{
		::safeRelease(m_pResult);
		ATLTRACE("Destroying CXPathHelper\n");
		#ifdef COUNT_HELPER
			--sm_Count;	
		#endif
	}

DECLARE_REGISTRY_RESOURCEID(IDR_XPATHHELPER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CXPathHelper)
	COM_INTERFACE_ENTRY(IXPathHelper)
	COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

// IXPathHelper
public:
	inline void putResult(CComObject<CXPathResult>* pResult);
	STDMETHOD(getData)(VARIANT v,long * retVal);
private:
	CComObject<CXPathResult>* m_pResult;
};

inline void CXPathHelper::putResult(CComObject<CXPathResult> *pResult)
{
	::safeRelease(m_pResult);
	m_pResult = pResult;
	m_pResult->AddRef();
}

#endif //__XPATHHELPER_H_
